package ps.guan.web.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;

import ps.guan.client.UserService;
import ps.guan.pojo.User;


@Controller
public class UserController {
	
	@Autowired
	private UserService userService;
	
	@RequestMapping("/user/index")
	@ResponseBody
	public Object getUser(){
		
		User user = this.userService.getUserById(1l);
		if (user ==null) {
			return "error";
		}
		return user;
		
	}
	
	@RequestMapping("/user/hello")
	@ResponseBody
	public String hello(HttpServletRequest request,HttpServletResponse response,ModelMap modelMap){
		
		
		return "hello ni hao";
		
	}
	@RequestMapping("/login")
	public String login(HttpServletRequest request,HttpServletResponse response,ModelMap modelMap){
		
		
		return "user/login";
		
	}
	
	@RequestMapping("/index")  
    public String hello(Map<String,Object> map){  
        map.put("name", "[Angel -- 守护天使]");  
        map.put("gender","1");//gender:性别，1：男；0：女；  
          
        List<Map<String,Object>> friends =new ArrayList<Map<String,Object>>();  
        Map<String,Object> friend = new HashMap<String,Object>();  
        friend.put("name", "张三");  
        friend.put("age", 20);  
        friends.add(friend);  
        friend = new HashMap<String,Object>();  
        friend.put("name", "李四");  
        friend.put("age", 22);  
        friends.add(friend);  
        map.put("friends", friends);  
        return "index";  
    }  

}